<template>
  <div class="remindInput">
    <div class="left">
      <div class="detail_main">
        <div class="detail_top">
          <h2>当前回访信息</h2>
        </div>
        <FormPanel ref="currentVisit" :list="formList" :cols="2" :isSubmitBtn="false" :collapse="false" :labelWidth="120" @formChange="changeHandle" />
      </div>
      <div class="detail_main">
        <div class="detail_top">
          <h2>上次回访信息</h2>
        </div>
        <FormPanel ref="lastVisit" :list="formList4" :cols="2" :isSubmitBtn="false" :collapse="false" :labelWidth="120" @formChange="changeHandle" />
      </div>
    </div>

    <div class="right">
      <div class="detail_main">
        <div class="detail_top">
          <h2>提醒信息</h2>
        </div>
        <div class="detail_containter">
          <FormPanel :list="formList2" :isSubmitBtn="false" :collapse="false" :labelWidth="120" :cols="2" @formChange="changeHandle2" />
          <ButtonArea :style="{ paddingLeft: '0px', float: 'right' }">
            <el-button type="primary" @click="openRemindHistory()">回访历史</el-button>
            <el-button v-if="vhide" type="primary" @click="showDia(2)">维修历史</el-button>
            <el-button v-if="vhide" type="primary" @click="openComplaint()">投诉录入</el-button>
          </ButtonArea>
          <div style="clear:both;">
            <ToggleTable v-if="type == 1" ref="ToggleTable" :rData="remindData"></ToggleTable>
            <ToggleText v-if="type == 2" ref="toggleText" :data="this.remindData" :remindSourcePath="this.remindSource"></ToggleText>
          </div>
          <div
            :style="{
              position: 'absolute',
              left: 0,
              bottom: 0,
              right: 0,
              zIndex: 9999,
              borderTop: '1px solid #e9e9e9',
              padding: '10px 20px',
              background: '#fff',
              textAlign: 'right'
            }"
          >
            <el-button type="primary" @click="saveMsg">{{ isTrace === 80581003 || isTrace === 80581004 ? '确定' : '保存' }}</el-button>
            <el-button type="primary" @click="exhale('0')">智能外呼</el-button>
            <el-button type="primary" @click="exhale('00')">加0外呼</el-button>
            <el-button @click="closeDialog">取 消</el-button>
          </div>
        </div>
      </div>
    </div>

    <!-- 监控 -->
    <Drawer :visible.sync="ismonitoring" title="监控车辆提醒" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <!-- isBtnAtion: 是否自动弹出; queryParams: 传入参数(格式见 props 内定义); confirm: 确定事件(选择的 活动，预约) -->
      <MonitoringModal :isAutoAtion="isMonitoringAutoAtion" :queryParams="monitoringQueryParams" @confirm="monitoringConfirm" @cancel="ismonitoring = false" />
    </Drawer>

    <!-- 投诉历史 -->
    <Drawer :visible.sync="showComplaintHistory" title="客诉单维护" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <complaintHistory ref="complaintHistory" :type="openType" :flag="openFlag" :rowData="rowData" @close="cancle(1)"></complaintHistory>
    </Drawer>

    <!-- 维修历史 -->
    <Drawer :visible.sync="showRepairHistory" title="维修历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <repairHistory ref="repairHistory" :getdata="repairHistoryData" @close="cancle(2)"></repairHistory>
    </Drawer>

    <!-- 销售回访信息 -->
    <Drawer :visible.sync="showSaleVisitFlag" title="销售回访信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <saleRemindHistory ref="saleRemindHistory" :resData="returnHisData" @close="closeRemindHistory(2)"></saleRemindHistory>
    </Drawer>
    <!-- 服务回访信息 -->
    <Drawer :visible.sync="showServiceVisitFlag" title="服务回访信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <serviceRemindHistory ref="serviceRemindHistory" :resData="returnHisData" @close="closeRemindHistory(2)"></serviceRemindHistory>
    </Drawer>
    <!-- 活动回访信息 -->
    <Drawer :visible.sync="showActivityVisitFlag" title="活动回访信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <activityRemindHistory ref="activityRemindHistory" :resData="returnHisData" @close="closeRemindHistory(2)"></activityRemindHistory>
    </Drawer>
    <!-- 二手车回访信息 -->
    <Drawer :visible.sync="showUsedCarVisitFlag" title="二手车回访信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <usedCarRemindHistory ref="usedCarRemindHistory" :resData="returnHisData" @close="closeRemindHistory(2)"></usedCarRemindHistory>
    </Drawer>
    <!-- 潜客回访信息 -->
    <Drawer :visible.sync="showSneakVisitFlag" title="潜客回访信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <sneakRemindHistory ref="sneakRemindHistory" :resData="returnHisData" @close="closeRemindHistory(2)"></sneakRemindHistory>
    </Drawer>
    <!-- 战败回访信息 -->
    <Drawer :visible.sync="showDefeatVisitFlag" title="战败回访信息" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <defeatRemindHistory ref="defeatRemindHistory" :resData="returnHisData" @close="closeRemindHistory(2)"></defeatRemindHistory>
    </Drawer>

    <!-- 提醒历史 -->
    <Drawer :visible.sync="showRemindHistory" title="提醒历史" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <RemindHistory :vin="chooseVin" :ownerNo="chooseOwnerNo" :visitType="visitType" :remindSource="2" @close="closeRemindHistory" />
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9999,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <el-button @click="closeRemindHistory">返 回</el-button>
      </div>
    </Drawer>

    <!-- 维修建议 -->
    <Drawer :visible.sync="showRepairSuggest" title="维修建议" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <!-- <RepairImport ref="RepairImport" :vin="chooseVin" @cancel="cancle(3)" /> -->
    </Drawer>

    <!-- 预约安排 -->
    <Drawer :visible.sync="showReservation" title="预约安排" width="1350" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <Precontract ref="Precontract" :Vin="chooseVin" :License="chooseLicense" @close="cancle(4)" />
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9999,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <el-button @click="cancle(3)">返 回</el-button>
      </div>
    </Drawer>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { notifyAction } from '@/utils/index';
import moment from 'moment';
import { searchRoleByCode } from '@/api/common/empSelect/index';
import dictCode from '@/utils/dictCode';
import ToggleTable from '@/pages/customerRepair/customerCare/maintenanceRemind/ToggleTable';
import ToggleText from '@/pages/customerRepair/customerCare/maintenanceRemind/toggleText';
import { queryRepairBusiness } from '@/api/repair/repairReception/repairBusinessManger';
import { retriveByControl, retriveByControlright, queryActivityValid } from '@/api/repair/repairReception/customer/monitoring.js';
import { addRemind, getActivityEntryVisitResultNews, addQuestion, getLastInfo, batchAddQuestion } from '@/api/customerRepair/customerCare/maintenanceRemind';
// import { getfindAllRepairType } from '@/api/repair/repairReception/customer/history';
import RemindHistory from '@/pages/customerRepair/customerCare/maintenanceRemind/visitHistory.vue';
import MonitoringModal from '@/pages/customerRepair/customerCare/maintenanceRemind/monitoring/Modal.vue';
import complaintHistory from '@/pages/customerRepair/customerComplaint/customerComplaintReception';
import repairHistory from '@/pages/repair/business/customer/Repairhistory/historypop.vue';
// import RepairImport from '@/pages/repair/repairReception/customer/repairImport/Modal.vue';
import Precontract from '@/pages/repair/repairReception/precontractArrange';
import { getModel } from '@/api/customerRepair/customerCare/insuranceDueRemind/index';
import { getDealerUser } from '@/api/part/partInventory/partInventory/index.js';

import saleRemindHistory from '@/pages/customerRepair/saleVisit/taskEntry/salesVisitHistory.vue';
import serviceRemindHistory from '@/pages/customerRepair/afterSaleVisit/resultEntry/salesVisitHistory.vue';
import activityRemindHistory from '@/pages/customerRepair/activityVisit/taskEntry/salesVisitHistory.vue';
import usedCarRemindHistory from '@/pages/customerRepair/usedCarVisit/taskEntry/salesVisitHistory.vue';
import sneakRemindHistory from '@/pages/customerRepair/activityVisit/taskDistribution/salesVisitHistory.vue';
import defeatRemindHistory from '@/pages/customerRepair/usedCarVisit/taskDistribution/salesVisitHistory.vue';

export default {
  name: 'remindInputs',
  components: {
    ToggleTable,
    ToggleText,
    RemindHistory,
    MonitoringModal,
    complaintHistory /* 投诉入口 */,
    repairHistory,
    // RepairImport,
    Precontract,

    saleRemindHistory /* 销售回访历史 */,
    serviceRemindHistory /* 售后回访历史 */,
    activityRemindHistory /* 活动回访历史 */,
    usedCarRemindHistory /* 二手车回访历史 */,
    sneakRemindHistory /* 潜客回访历史 */,
    defeatRemindHistory /* 战败回访历史 */
  },
  mixins: [dictionary],
  // props: {
  //   remindData: {
  //     type: Object,
  //     default: () => ({})
  //   }
  // },
  props: ['remindData', 'buttonType', 'remindSource', 'visitType'],
  data() {
    return {
      /* 投诉单所需数据字段----begin */
      openType: 'create',
      openFlag: null,
      rowData: {},
      /* 投诉单所需数据字典----end */
      /* 呼叫中心所需字段----begin */
      afterVal: '',
      HFDH: '',
      ctiUrl: '',
      callid: '',
      /* 呼叫中心所需字段 ----end*/
      type: this.buttonType || 2,
      ismonitoring: false, // 监控
      isMonitoringAutoAtion: false,
      monitoringQueryParams: {},
      // 提示信息
      tiShiInfo: [],
      // 提示信息 监控表格
      dataSource: [],
      dataSource3: [], //  服务活动
      formList: this.createFormList(),
      formList1: this.createdFrom1(),
      formList2: this.createdFrom2(),
      formList4: this.createFormList4(),
      fetchApi2: queryRepairBusiness,
      fetchParams2: { xhrAbort: true },
      columns1: this.createdTable1(),
      columns2: this.createdTable2(),
      columns3: this.createdTable3(),
      dataList2: [],
      showRemindHistory: false,
      isTrace: null,
      chooseVin: null, // 选中的vin
      chooseLicense: null, // 选中的license
      chooseOwnerNo: null, // 选中的数据的ownerNo
      repairHistoryData: {}, // 维修历史数据
      showRepairHistory: false, // 维修历史
      showRepairSuggest: false, // 建议维修
      showComplaintHistory: false, // 投诉历史
      showReservation: false, // 预约安排
      remindSourcePath: null, // 数据来源
      isMustFlag: true,
      flag: true,
      vhide: true,
      resData: [],
      vin: null,
      /* 回访历史 */
      showSaleVisitFlag: false,
      showServiceVisitFlag: false,
      showActivityVisitFlag: false,
      showUsedCarVisitFlag: false,
      showSneakVisitFlag: false,
      showDefeatVisitFlag: false,
      returnHisData: {} // 回访历史数据
    };
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.remindSourcePath = this.remindSource;
    });
    this.typeSelect();
    this.queryEmpolyeeInfo();
    this.getRepairHistoryTable();
    this.initForm2();
    this.getLastInfo();
    this.isTrace = this.remindData.TRACE_STATUS;
    this.after();
    if (this.visitType == 15721005 || this.visitType == 15721006) {
      this.vhide = false;
    } else if (this.visitType === 15721001) {
      this.formList2.find(item => item.fieldName === 'sxrq').hidden = false;
      this.formList2.find(item => item.fieldName === 'jsrq').hidden = false;
    }
    this.formList.find(item => item.fieldName === 'hfzt').initialValue = 15921001;
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '回访单号',
          fieldName: 'hfdh',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT_NUMBER',
          label: '满意度打分',
          fieldName: 'myddfs',
          initialValue: undefined,
          // disabled: true
          rules: [{ required: true, message: '请填写分数', trigger: 'change' }]
        },
        {
          type: 'SELECT',
          label: '回访状态',
          fieldName: 'hfzt',
          initialValue: '',
          itemList: this.createDictList('1592'),
          rules: [{ required: true, message: '请选择回访状态', trigger: 'change' }],
          change: val => this.selectChangeRule(val)
        },
        {
          type: 'CHECKBOX',
          label: '免打扰',
          fieldName: 'sfmdr',
          options: { trueValue: 10041001, falseValue: 10041002 }
        },
        {
          type: 'SELECT',
          label: '回访状态原因',
          fieldName: 'hfztyy',
          initialValue: '',
          itemList: this.createDictList('8084')
        },
        {
          type: 'SELECT',
          label: '回访结果',
          fieldName: 'shfjg',
          initialValue: '',
          itemList: this.createDictList('1075'),
          rules: [{ required: true, message: '请选择回访结果', trigger: 'change' }]
        },
        {
          type: 'CHECKBOX',
          label: '需要回访标识',
          fieldName: 'xzhf',
          options: { trueValue: 10041001, falseValue: 10041002 },
          change: val => this.selectChangehf(val)
        },
        {
          type: 'DATE',
          label: '下次回访日期',
          fieldName: 'nextVisitDate',
          initialValue: '',
          disabled: true,
          rules: []
        },
        {
          type: 'TEXT_AREA',
          label: '其他建议',
          fieldName: 'qtjy',
          selfCols: 1.5,
          rows: 2
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'bz',
          selfCols: 1.5,
          rows: 2,
          maxlength: 1000
        },

        {
          type: 'SELECT',
          label: '不满意原因',
          fieldName: 'bmyyyfl',
          initialValue: '',
          itemList: this.createDictList('8201')
        },
        {
          type: 'TEXT_AREA',
          label: '不满意原因描述',
          fieldName: 'BMYYYMX',
          selfCols: 1.5,
          rows: 2,
          maxlength: 100
        }
      ];
    },
    createdFrom1() {
      return [
        {
          type: 'TEXT_AREA',
          label: '提醒内容',
          fieldName: 'DEALER_CODE',
          initialValue: ''
        }
      ];
    },
    createFormList4() {
      return [
        {
          type: 'INPUT',
          label: '回访单号',
          fieldName: 'hfdh',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '回访人',
          fieldName: 'hfrm',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '回访时间',
          fieldName: 'hfrq',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '满意度打分',
          fieldName: 'myddf',
          disabled: true
        },
        {
          type: 'SELECT',
          label: '回访状态',
          fieldName: 'hfzt',
          initialValue: '',
          disabled: true,
          itemList: this.createDictList('1592')
        },
        {
          type: 'SELECT',
          label: '回访状态原因',
          fieldName: 'hfztyy',
          initialValue: '',
          disabled: true,
          itemList: this.createDictList('8084')
        },
        {
          type: 'SELECT',
          label: '回访结果',
          fieldName: 'hfjg',
          initialValue: '',
          disabled: true,
          itemList: this.createDictList('1075')
        },
        {
          type: 'TEXT_AREA',
          label: '其他建议',
          fieldName: 'qtjy',
          disabled: true,
          selfCols: 1.5,
          rows: 2
        },
        {
          type: 'TEXT_AREA',
          label: '备注',
          fieldName: 'bz',
          disabled: true,
          selfCols: 1.5,
          rows: 2,
          maxlength: 100
        }
      ];
    },
    monitoringFunBefore() {
      this.monitoringQueryParams = {
        MODEL: this.remindData.cxingmc,
        SERIES: this.remindData.cximc,
        // 活动 出险 预约 新能源 参数
        LICENSE: this.remindData.pzh,
        vin: this.remindData.dph,
        ownerNo: this.remindData.ownerNo,
        engineNo: this.remindData.engineNo,
        BRAND: this.remindData.brand,
        isRepairOrder: 'REPAIR_ORDER_TAG',
        dmsFuncId: '35100010',
        createDate: moment().format('YYYY-MM-DD HH-mm'),
        _: new Date().getTime()
      };
    },

    monitoringAutoFun() {
      this.isMonitoringAutoAtion = true;
      this.monitoringFunBefore();
      this.ismonitoring = true;
    },
    monitoringBtnFun() {
      this.isMonitoringAutoAtion = false;
      this.monitoringFunBefore();
      this.ismonitoring = true;
    },

    monitoringConfirm(obj) {
      this.ismonitoring = false;
    },

    // 显示弹框
    showDia(type) {
      this.chooseVin = this.remindData.vin;
      this.chooseLicense = this.remindData.license;
      this.chooseOwnerNo = this.remindData.owner_no;
      switch (type) {
        case 1:
          // 打开投诉历史
          this.chooseVin = this.remindData.dph;
          this.showComplaintHistory = true;
          break;
        case 2:
          // 打开维修历史
          this.repairHistoryData = {
            LICENSE: this.remindData.pzh,
            VIN: this.remindData.dph,
            ENGINE_NO: this.remindData.engineNo,
            OWNER_NAME: this.remindData.khmc,
            FH_FLAG: 'true' // 根据这个参数去查询所有状态的结算单的维修历史
          };
          window.console.log(this.repairHistoryData);
          this.showRepairHistory = true;
          break;
        case 3:
          // 打开建议维修
          this.showRepairSuggest = true;
          break;
        case 4:
          // 打开预约安排
          this.showReservation = true;
          break;
      }
    },

    // 取消,关闭弹框
    cancle(type) {
      switch (type) {
        case 1:
          // 关闭投诉历史
          this.showComplaintHistory = false;
          break;
        case 2:
          // 关闭维修历史
          this.showRepairHistory = false;
          break;
        case 3:
          // 关闭建议维修
          this.showRepairSuggest = false;
          break;
        case 4:
          // 关闭预约安排
          this.showReservation = false;
          break;
      }
    },

    initForm2() {
      // let newStr = [];
      // for (let [key, val] of Object.entries(this.remindData)) {
      //   let param = {
      //     fieldName: key,
      //     value: val
      //   };
      //   newStr.push(param);
      // }
      console.log('回访单号', this.remindData.hfdh);
      this.formList2.forEach(x => {
        x.initialValue = this.remindData[x.fieldName];
      });
      this.formList.forEach(x => {
        if (x.fieldName == 'hfdh') {
          x.initialValue = this.remindData.hfdh;
        } else {
          x.initialValue = '';
        }
      });
      this.formList.find(item => item.fieldName === 'myddfs').initialValue = undefined;
      // this.syncFormListData(newStr);
      // this.formList2.find(item => item.fieldName === 'sxrq').initialValue = this.remindData.sxrq;
      // this.formList2.find(item => item.fieldName === 'jsrq').initialValue = this.remindData.jsrq;
    },

    // 驼峰转换  RO_NO --> roNo
    camelcase(str) {
      let arr = str.split('_');
      let upper = arr.map((val, index) => {
        let lowStr = val.toLowerCase();
        if (index) {
          lowStr = lowStr.charAt(0).toLocaleUpperCase() + lowStr.slice(1);
        }
        return lowStr;
      });
      return upper.join('');
    },

    // 把返回的数据赋值给表单
    syncFormListData(dataList) {
      const formList = [...this.formList2];
      const formFieldNames = formList.map(x => x.fieldName);
      dataList.forEach(x => {
        if (formFieldNames.includes(x.fieldName)) {
          let target = formList.find(k => k.fieldName == x.fieldName);
          if (!target) return;
          target.initialValue = x.value;
        }
      });

      const formListdh = [...this.formList];
      const formFieldNames1 = formListdh.map(x => x.fieldName);
      dataList.forEach(x => {
        if (formFieldNames1.includes(x.fieldName)) {
          let target = formListdh.find(k => k.fieldName == x.fieldName);
          if (!target) return;
          target.initialValue = x.value;
        }
      });

      this.formList.find(item => item.fieldName === 'myddfs').initialValue = undefined;
      this.formList.find(item => item.fieldName === 'hfztyy').initialValue = null;
      this.formList.find(item => item.fieldName === 'shfjg').initialValue = null;
      this.formList.find(item => item.fieldName === 'xzhf').initialValue = null;
      this.formList.find(item => item.fieldName === 'qtjy').initialValue = null;
    },
    createdFrom2() {
      return [
        {
          type: 'INPUT',
          label: '车主',
          fieldName: 'khmc',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车牌号',
          fieldName: 'pzh',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'dph',
          disabled: true,
          initialValue: ''
        },
        {
          type: 'INPUT',
          label: '车主电话',
          fieldName: 'khyddh',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '联系人',
          fieldName: 'lxrmc',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '联系人电话',
          fieldName: 'lxryddh',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'cximc',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'cxingmc',
          initialValue: '',
          disabled: true
        },
        {
          type: 'INPUT',
          label: '送修日期',
          fieldName: 'sxrq',
          dateFormat: 'yyyy-MM-dd',
          hidden: true,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '结算日期',
          fieldName: 'jsrq',
          dateFormat: 'yyyy-MM-dd',
          hidden: true,
          disabled: true
        },
        {
          type: 'INPUT',
          label: '服务顾问',
          fieldName: 'fwgw',
          disabled: true
        }
      ];
    },

    createdTable1() {
      return [
        {
          title: '序号',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '监控信息',
          dataIndex: 'MESSAGE',
          sorter: true,
          filter: true
        }
      ];
    },
    createdTable2() {
      return [
        {
          title: '序号',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          sorter: true,
          filter: true
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          sorter: true,
          filter: true,
          filterItems: []
        },
        {
          title: '开单日期',
          dataIndex: 'RO_CREATE_DATE',
          sorter: true,
          filter: true
        },
        {
          title: '工时费',
          dataIndex: 'LABOUR_AMOUNT',
          sorter: true,
          filter: true
        },
        {
          title: '材料费',
          dataIndex: 'REPAIR_PART_AMOUNT',
          sorter: true,
          filter: true
        },
        {
          title: '维修总金额',
          dataIndex: 'REPAIR_AMOUNT',
          sorter: true,
          filter: true
        }
      ];
    },
    createdTable3() {
      return [
        {
          title: '序号',
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '活动编号',
          dataIndex: 'ACTIVITY_CODE',
          sorter: true,
          filter: true
          // render: props => {
          //   return <span>{props.row.ACTIVITY_CODE}</span>;
          // }
        },
        {
          title: '活动名称',
          dataIndex: 'ACTIVITY_NAME',
          sorter: true,
          filter: true
          // render: props => {
          //   return <span>{props.row.ACTIVITY_NAME}</span>;
          // }
        },
        {
          title: '活动类型',
          dataIndex: 'ACTIVITY_TYPE',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{this.createDictText(props.row.ACTIVITY_TYPE, '8080')}</span>;
          }
        },
        {
          title: '开始日期',
          dataIndex: 'startTime',
          sorter: true,
          filter: true,
          render: props => {
            return <span>{props.row.startTime}</span>;
          }
        },
        {
          title: '结束日期',
          dataIndex: 'END_DATE',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '活动总金额',
          dataIndex: 'ACTIVITY_AMOUNT',
          sorter: true,
          filter: true
        }
      ];
    },
    changeHandle(val) {
      this.resData = Object.assign({}, val);
    },
    changeHandle1(val) {},
    changeHandle2(val) {},
    changeHandle3(val) {},

    async getRepairType(val) {
      let res = await getfindAllRepairType();
      // console.log(res,'res')
      let arr = [];
      res.data.forEach(x => {
        arr.push({ text: x.REPAIR_TYPE_NAME, value: x.REPAIR_TYPE_CODE });
      });
      val.forEach(x => {
        arr.forEach(y => {
          if (x.REPAIR_TYPE_CODE == y.value) {
            // console.log(y);
            x.REPAIR_TYPE_CODE = y.text;
          }
        });
      });
    },

    // 页面管控
    typeSelect() {
      this.formList2.map(x => {
        x.disabled = true;
      });
    },
    // 查询所有车型
    async queryModel() {
      const res = await getModel();
      this.formList2.find(x => x.fieldName === 'model').itemList = res.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_ID + '' }));
      const resUser = await getDealerUser();
      // 服务顾问
      this.formList2.find(x => x.fieldName === 'lastConsultantId').itemList = resUser.data.map(x => ({ value: x.userId, text: x.employeeName }));
    }, // 查询上次回访信息

    async getLastInfo() {
      const queryParams = {
        ownerCode: this.remindData.ownerCode,
        khmc: this.remindData.khmc,
        khxm: this.remindData.khxm,
        dph: this.remindData.dph,
        cph: this.remindData.cph,
        returnVisitInfoId: this.remindData.returnVisitInfoId
      };
      const res = await getLastInfo(queryParams);
      window.console.log(res.data);
      let tableStr = [];
      for (let [key, val] of Object.entries(res.data[0])) {
        let param = {
          fieldName: key,
          value: val
        };
        tableStr.push(param);
      }

      const formList = [...this.formList4];
      const formFieldNames = formList.map(x => x.fieldName);
      tableStr.forEach(x => {
        if (formFieldNames.includes(x.fieldName)) {
          let target = formList.find(k => k.fieldName == x.fieldName);
          if (!target) return;
          target.initialValue = x.value;
        }
      }); // this.formList2.find(x => x.fieldName === 'model').itemList = res.data.map(x => ({ text: x.MODEL_NAME, value: x.MODEL_ID + '' }));11111
    },

    selectChangeRule(val) {
      if (val === 15921004) {
        this.formList.find(x => x.fieldName === 'myddfs').rules = [{ required: false, message: '', trigger: 'change' }];
        this.formList.find(x => x.fieldName === 'shfjg').rules = [{ required: false, message: '', trigger: 'change' }];
        this.formList.find(x => x.fieldName === 'xzhf').initialValue = 10041002;
        this.formList.find(x => x.fieldName === 'nextVisitDate').initialValue = null;
        this.formList.find(x => x.fieldName === 'nextVisitDate').disabled = false;
      } else if (val === 15921003) {
        this.formList.find(x => x.fieldName === 'myddfs').rules = [{ required: true, message: '请填写分数', trigger: 'change' }];
        this.formList.find(x => x.fieldName === 'shfjg').rules = [{ required: true, message: '请选择回访结果', trigger: 'change' }];
        this.formList.find(x => x.fieldName === 'xzhf').initialValue = 10041002;
        this.formList.find(x => x.fieldName === 'nextVisitDate').initialValue = null;
        this.formList.find(x => x.fieldName === 'nextVisitDate').disabled = true;
      } else if (val === 15921002) {
        this.formList.find(x => x.fieldName === 'myddfs').rules = [{ required: false, message: '', trigger: 'change' }];
        this.formList.find(x => x.fieldName === 'shfjg').rules = [{ required: false, message: '', trigger: 'change' }];
        this.formList.find(x => x.fieldName === 'xzhf').initialValue = 10041001;
        this.formList.find(x => x.fieldName === 'nextVisitDate').disabled = false;
      } else {
        this.formList.find(x => x.fieldName === 'myddfs').rules = [{ required: true, message: '请填写分数', trigger: 'change' }];
        this.formList.find(x => x.fieldName === 'shfjg').rules = [{ required: true, message: '请选择回访结果', trigger: 'change' }];
        this.formList.find(x => x.fieldName === 'xzhf').initialValue = 10041002;
        this.formList.find(x => x.fieldName === 'nextVisitDate').initialValue = null;
        this.formList.find(x => x.fieldName === 'nextVisitDate').disabled = true;
      }
    },

    openRemindHistory() {
      this.returnHisData = this.remindData;
      const visitType = this.returnHisData.visitType;
      if (visitType === 15721001) {
        this.showSaleVisitFlag = false;
        this.showServiceVisitFlag = true;
        this.showActivityVisitFlag = false;
        this.showUsedCarVisitFlag = false;
        this.showSneakVisitFlag = false;
        this.showDefeatVisitFlag = false;
      } else if (visitType === 15721002) {
        this.showSaleVisitFlag = true;
        this.showServiceVisitFlag = false;
        this.showActivityVisitFlag = false;
        this.showUsedCarVisitFlag = false;
        this.showSneakVisitFlag = false;
        this.showDefeatVisitFlag = false;
      } else if (visitType === 15721003) {
        this.showSaleVisitFlag = false;
        this.showServiceVisitFlag = false;
        this.showActivityVisitFlag = false;
        this.showUsedCarVisitFlag = true;
        this.showSneakVisitFlag = false;
        this.showDefeatVisitFlag = false;
      } else if (visitType === 15721004) {
        this.showSaleVisitFlag = false;
        this.showServiceVisitFlag = false;
        this.showActivityVisitFlag = true;
        this.showUsedCarVisitFlag = false;
        this.showSneakVisitFlag = false;
        this.showDefeatVisitFlag = false;
      } else if (visitType === 15721005) {
        this.showSaleVisitFlag = false;
        this.showServiceVisitFlag = false;
        this.showActivityVisitFlag = false;
        this.showUsedCarVisitFlag = false;
        this.showSneakVisitFlag = true;
        this.showDefeatVisitFlag = false;
      } else {
        this.showSaleVisitFlag = false;
        this.showServiceVisitFlag = false;
        this.showActivityVisitFlag = false;
        this.showUsedCarVisitFlag = false;
        this.showSneakVisitFlag = false;
        this.showDefeatVisitFlag = true;
      }
    },

    openComplaint() {
      this.openType = 'create';
      this.openFlag = this.remindData.visitType + '';
      this.rowData = this.remindData;
      this.showComplaintHistory = true;
    },

    // 关闭历史提醒
    closeRemindHistory(data) {
      // this.showRemindHistory = false;
      this.showSaleVisitFlag = false;
      this.showServiceVisitFlag = false;
      this.showActivityVisitFlag = false;
      this.showUsedCarVisitFlag = false;
      this.showSneakVisitFlag = false;
      this.showDefeatVisitFlag = false;
    },

    // 提醒内容
    async queryEmpolyeeInfo() {
      this.chooseOwnerNo = this.remindData.ownerNo;
      this.chooseVin = this.remindData.vin;

      let obj = {
        vin: this.remindData.vin,
        LICENSE: this.remindData.license
      };
      // const res = await retriveByControl(obj);
      // // console.log(res,'neirong')
      // this.tiShiInfo = res.data;
    },

    // 查询 监控信息
    async getMonitoryTable() {
      const params = {
        sort: 'IS_VALID',
        order: 'asc',
        engineNo: this.remindData.engineNo || '',
        MODEL: this.remindData.modelCode || '',
        SERIES: this.remindData.seriesCode || '',
        RONO: this.remindData.roNo || '',
        LICENSE: this.remindData.license,
        vin: this.remindData.vin,
        ownerNo: this.remindData.ownerNo,
        isRepairOrder: 'REPAIR_ORDER_TAG',
        BRAND: this.remindData.brandCode || '',
        MILEAGE: this.remindData.lastMaintainMileage,
        createDate: moment().format('YYYY-MM-DD HH-mm'),
        dmsFuncId: '35100010',
        _: '1567144192282'
      };
      const res = await retriveByControlright(params);
      this.dataSource = res.data;
    },

    // 工单历史
    getRepairHistoryTable() {
      let vin = this.remindData.vin;
      // 增加参数 过滤 2年内单据
      let type = 'twoYear';
      this.fetchParams2 = Object.assign({}, { vin, type }, { xhrAbort: false });
    },

    // 服务活动
    async queryActivityValid() {
      const params = {
        sort: 'IS_VALID',
        order: 'asc',
        engineNo: this.remindData.engineNo || '',
        MODEL: this.remindData.modelCode || '',
        SERIES: this.remindData.seriesCode || '',
        RONO: this.remindData.roNo || '',
        LICENSE: this.remindData.license,
        vin: this.remindData.vin,
        ownerNo: this.remindData.ownerNo,
        isRepairOrder: 'REPAIR_ORDER_TAG',
        BRAND: this.remindData.brandCode || '',
        MILEAGE: this.remindData.lastMaintainMileage,
        createDate: moment().format('YYYY-MM-DD HH-mm'),
        dmsFuncId: '35100010',
        IS_ACTITY_BOOKING: '10041001',
        _: '1567144192282'
      };
      const res = await queryActivityValid(params);
      // console.log('查询可选活动', params, res);
      this.dataSource3 = res.data;
    },

    // 保存
    async saveMsg() {
      const [err, data] = await this.$refs.currentVisit.GET_FORM_DATA();
      if (err && err['shfjg']) {
        notifyAction(err['shfjg'][0]['message'], 'error');
        return;
      }

      let tableList = this.$refs.ToggleTable.tableList;
      // let formList = this.$refs.ToggleTable.formList;
      // 当问卷类型设置的为必填项时，跟踪状态选择成功结束跟踪或者失败结束跟踪时，需要判断必填项的答案要必填，没有填需要弹出提示信息不能保存，当跟踪状态选择未跟踪或者继续跟踪时，答案选项可以不填。
      console.log(tableList, 'tablelist');
      // console.log(formList, 'formList');
      // tableList.forEach(x => {
      //   // console.log(x, 'xxxx');
      //   if (x.isMustFilled === 10041001) {
      //     if (!x.answer) {
      //       this.isMustFlag = false;
      //       return;
      //     } else {
      //       this.isMustFlag = true;
      //     }
      //   }
      // });
      // if (this.isMustFlag) {
      this.saveBtn();
      // } else {
      //   this.$message({
      //     type: 'warning',
      //     message: '问卷有必填项，请填写必填项!'
      //   });
      // }
    },

    async saveBtn() {
      this.resData = null;
      this.$refs.currentVisit.SUBMIT_FORM();
      // let questionnaireId = this.$refs.ToggleTable.questionnaireId;
      let tableList = this.$refs.ToggleTable.tableList;
      // this.resData.dph = this.remindData.dph;
      // this.resData.visitType = this.remindData.visitType;
      const sendData = Object.assign({}, this.resData, { dph: this.remindData.dph }, { visitType: this.remindData.visitType });
      window.console.log(sendData);

      let obj = Object.assign(
        {},
        sendData,
        { list: tableList },
        { returnVisitInfoId: this.remindData.returnVisitInfoId },
        { url: this.ctiUrl },
        { callid: this.callid },
        { dph: this.remindData.dph },
        { visitType: this.remindData.visitType },
        // 保存时，主单部分信息一起保存
        { ownerNo: this.remindData.ownerNo },
        { xsgw: this.remindData.xsgw },
        { khmc: this.remindData.khmc },
        { khdh: this.remindData.khdh },
        { lxr: this.remindData.lxr },
        { lxrsj: this.remindData.lxrsj },
        { lxryddh: this.remindData.lxryddh },
        { cximc: this.remindData.cximc },
        { cxingmc: this.remindData.cxingmc },
        { khdz: this.remindData.khdz },
        { cjrq: this.remindData.cjrq },
        { pzh: this.remindData.pzh },
        // 保存时，新增字段
        { fwgw: this.remindData.fwgw },
        { jszt: this.remindData.jszt == '已结算' ? 80491003 : '' },
        { jsrq: this.remindData.jsrq },
        { xslc: this.remindData.xslc },
        { sxrq: this.remindData.sxrq },
        { bgsscbs: this.remindData.bgsscbs },
        { fblxsj: this.remindData.fblxsj },
        { gcrq: this.remindData.gcrq }
      );

      // if (!tableList.length) {
      //   return this.$notify.warning({ title: '提示信息', message: '请先选择问题' });
      // }
      let queryObj = Object.assign({}, { dph: this.remindData.dph }, { visitType: this.remindData.visitType });
      const res1 = await getActivityEntryVisitResultNews(queryObj);

      if (res1.resultCode === 200) {
        const whfts = res1.data.rows[0].WHFSL;
        if (whfts === 1) {
          /* 直接执行 */
          const res = await addQuestion(obj);
          if (res.resultCode === 200) {
            this.$notify.success({
              title: '提示信息',
              message: '保存成功！'
            });
            this.$emit('close', false, 'refresh');
          }
        } else {
          const confirmMassage = '现在共有' + (whfts - 1) + '单据可关联回访，是否关联回访';
          this.$confirm(confirmMassage, '提示', {
            confirmButtonText: '是',
            cancelButtonText: '否',
            type: 'warning'
          })
            .then(async () => {
              /* 批量回访的方法 */
              let res2 = await batchAddQuestion(obj);
              if (res2.resultCode === 200) {
                this.$notify.success({
                  title: '提示信息',
                  message: '保存成功！'
                });
              }
              this.$emit('close', false, 'refresh');
            })
            .catch(() => {
              const res = addQuestion(obj);
              if (res.resultCode === 200) {
                this.$notify.success({
                  title: '提示信息',
                  message: '保存成功！'
                });
              }
              this.$emit('close', false, 'refresh');
            });
        }
      }
    },

    // 取消
    closeDialog() {
      this.$emit('close', false);
    },
    selectChangehf(val) {
      if (val == 10041001) {
        this.formList.find(item => item.fieldName === 'nextVisitDate').disabled = false;
        this.formList.find(item => item.fieldName === 'nextVisitDate').rules = [{ required: true, message: '请选择下次回访时间' }];
      } else {
        this.formList.find(item => item.fieldName === 'nextVisitDate').disabled = true;
        this.formList.find(item => item.fieldName === 'nextVisitDate').initialValue = '';
        this.formList.find(item => item.fieldName === 'nextVisitDate').rules = [];
      }
    },
    // 获取不满意原因
    getBmySun(val, num) {
      if (val == 82011001) {
        // 获取子类分类原因
        this.formList[num].itemList = this.createDictList('8201');
      } else if (val == 82011002) {
        this.formList[num].itemList = this.createDictList('8401');
      } else if (val == 82011003) {
        this.formList[num].itemList = this.createDictList('8501');
      } else if (val == 82011004) {
        this.formList[num].itemList = this.createDictList('8601');
      } else if (val == 82011005) {
        this.formList[num].itemList = this.createDictList('8701');
      } else if (val == 82011006) {
        this.formList[num].itemList = this.createDictList('8801');
      }
    },
    // 呼出系统
    exhale(a) {
      let phone = a + this.remindData.lxryddh; // 联系人电话
      let userData = {
        userData: {
          HFDH: this.remindData.HFDH,
          OWNER_CODE: this.remindData.ownerCode,
          OWNER_NAME: this.remindData.khmc,
          date: moment().format('YYYY-MM-DD hh:MM:SS')
        }
      };
      if (CallCenter.isLogin()) {
        CallCenter.callout(phone, null, null, null, null, userData);
        this.HFDH = this.remindData.HFDH;
      } else {
        this.$notify.warning({ title: '提示信息', message: '没有外呼权限!' });
      }
    },
    after() {
      let that = this;
      CallCenter.addEventListener('after', function(json) {
        console.log('验证是否监听到了after方法=============================>true');
        console.log('返回值================================>begin');
        console.log('返回值录音第一段================================>', json.recordDownloadUrl);
        console.log('返回值录音第二段================================>', json.mediano);
        console.log('返回值录音第三段================================>', json.filename);
        let url = json.recordDownloadUrl + '/' + json.mediano + '?file=' + json.filename;
        console.log('返回值录音路径================================>', url);
        let getCallId = json.callid;
        console.log('返回值CALLID================================>', getCallId);
        that.ctiUrl = url;
        console.log('返回URL值录音后台传递================================>', that.ctiUrl);
        that.callid = getCallId;
        console.log('返回CALLID值录音后台传递================================>', that.callid);
      });
    }
  }
};
</script>
<style lang="less" scoped>
.remindInput {
  width: 100%;

  .left {
    width: 43%;
    float: left;

    .detail_main {
      border: 1px solid #ebeef5;
      margin-bottom: 10px;

      .detail_top {
        background: #f2f2f2;
        border-bottom: 1px solid #ebeef5;
        height: 25px;
        line-height: 25px;
        padding: 0 4px;
        padding-right: 2px;
      }

      .detail_containter {
        padding-top: 10px;
      }
    }
  }

  .right {
    width: 57%;
    float: left;
    box-sizing: border-box;
    padding: 0 4px;

    .detail_main {
      border: 1px solid #ebeef5;
      margin-bottom: 10px;

      .detail_top {
        background: #f2f2f2;
        border-bottom: 1px solid #ebeef5;
        height: 25px;
        line-height: 25px;
        padding: 0 10px;
        padding-right: 10px;
      }

      .detail_containter {
        padding-top: 10px;
      }
    }
  }
}
</style>
